#include <bits/stdc++.h>
using namespace std;

int ispalindrome(int n) {
	int _n = n;
	int temp = 0;
	while (_n >= 1) {
		temp *= 10;
		temp += _n % 10;
		_n /= 10;
	}
	if (temp == n) {
		return 1;
	} else {
		return 0;
	}
}

int isprime(int n) {
	if (n <= 1) {
		return 0;
	}
	for (int i = 2; i < sqrt(n) + 1; i++) {
		if (n % i == 0) {
			return 0;
		}
	}
	return 1;

}

int arr[10000000] = {0};

int main() {
	int start = 0, end = 0;
	int j = 0;
	cin >> start >> end;
	for (int i = start; i <= end; i++) {
		if (isprime(i)) {
			if (ispalindrome(i)) {
				arr[j] = i;
				j++;
			}
		}
	}
	for (int i = 0; i < j; i++) {
		cout << arr[i] << endl;
	}
	return 0;
}